// pages/station/station.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalPrice:0,
    navId:"classic",
    leftId:"activity",
    data:[
      {
      uid:1,
      cid:1,
      type:"activity",
      name:"活动商品",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:2,
      cid:2,
      type:"drink",
      name:"可口可乐(瓶装)",
      specs:"500ml x 12",
      price:"1.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:3,
      cid:3,
      type:"drink",
      name:"百事可乐(罐装)",
      specs:"1919ml x 810",
      price:"145.1",
      image:"/static/images/project/project.png"
    },
    {
      uid:4,
      cid:4,
      name:"新品",
      type:"new",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:5,
      cid:5,
      name:"纸巾",
      type:"daily",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:6,
      cid:6,
      name:"纸巾",
      type:"daily",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:7,
      cid:7,
      name:"纸巾",
      type:"daily",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:8,
      cid:8,
      name:"纸巾",
      type:"daily",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    },
    {
      uid:9,
      cid:9,
      name:"纸巾",
      type:"daily",
      specs:"330ml x 12",
      price:"30.0",
      image:"/static/images/project/project.png"
    }
  ]
  },
  init(){
    let d=this.data.data
    for (let i = 0; i < this.data.data.length; i++) {
      this.data.data[i].num=0
    }
    this.setData({
      data:d
    });
  },
  updateSum(){
    let sum=0;
    for (let i = 0; i < this.data.data.length; i++) {
      sum+=this.data.data[i].num*this.data.data[i].price
    }
    this.setData({
      totalPrice:sum
    });
  },
  add(e){
    let id = e.target.dataset.id
    let arrObj = this.data.data.find((item)=>{return item.cid== id})
    arrObj.num++;
    let d=this.data.data;
    this.setData({
      data:d
    });
    this.updateSum()
  },
  minus(e){
    let id = e.target.dataset.id
    let arrObj = this.data.data.find((item)=>{return item.cid== id})
    arrObj.num--;
    let d=this.data.data;
    this.setData({
      data:d
    });
    this.updateSum()
  },
  changeNav(e){
    let navId=e.currentTarget.id;
    this.setData({
      navId
    })
    // wx.showLoading({
    //   title: '正在加载',
    // })
    // this.getProjectList(this.data.navId);
    // console.log(this.data.navId)
  },
  changeLeftNav(e){
    let leftId=e.currentTarget.id;
    this.setData({
      leftId
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})